﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PictureBoard4.Shape
{
    /// <summary>
    /// 椭圆
    /// </summary>
   public class Ellipse:Shape
    {
     //起始坐标
       public Point StartPoint { get; set; }
       //结束坐标
        public Point EndPoint { get; set; }
        public override void Add(System.Drawing.Point p)
        {
            if (StartPoint == EndPoint)
                StartPoint = p;
            else
                EndPoint = p;
        }

        public override bool Draw(System.Drawing.Graphics g)
        {
            Pen pen = new Pen(Tool.SColor, Tool.SWidth);
            int realStartX = Math.Min(StartPoint.X, EndPoint.X);
            int realStartY = Math.Min(StartPoint.Y, EndPoint.Y);
            int realEndX = Math.Max(StartPoint.X, EndPoint.X);
            int realEndY = Math.Max(StartPoint.Y, EndPoint.Y);
            int minStartX = StartPoint.X, minStartY = EndPoint.Y, maxEndX = 0, maxEndY = 0;
            minStartX = Math.Min(minStartX, realStartX);
            minStartY = Math.Min(minStartY, realStartY);
            maxEndX = Math.Max(maxEndX, realEndX);
            maxEndY = Math.Max(maxEndY, realEndY);
            //以下是为了获取最大重绘矩形。
            Rectangle refeshRect = new Rectangle(minStartX, minStartY, maxEndX - minStartX, maxEndY - minStartY);
            refeshRect.Inflate(1, 1);//重绘矩形的大小扩展1个单位
            g.DrawEllipse(pen, refeshRect);
            return true;
        }

        public override bool GetBound(ref System.Drawing.Point StartPoint, ref System.Drawing.Point EndPoint)
        {
            StartPoint = this.StartPoint;
            EndPoint = this.EndPoint;
            return true;


        }

        public override void Move(System.Drawing.Point point)
        {
         
            if (point.X != 0)
            {
                Point TempStartPoint = StartPoint;
                Point TempEndPoint = EndPoint;

                StartPoint = new Point(TempStartPoint.X + point.X, TempStartPoint.Y + point.Y);
                EndPoint = new Point(TempEndPoint.X + point.X, TempEndPoint.Y + point.Y);
            }
        }
    }
}
